 var setting = {
 		    check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			} 
			,
	        callback:
	        {
	          beforeCheck: beforeCheck
	        }
		};

jQuery(function()
    {
    	
		loadRoleFun();
    }
	);


function beforeCheck(treeId, treeNode)
{
    if(treeNode.superadmin=="Y")
    {
      return false;
    }
    return true;
}

//加载角色功能函数
function loadRoleFun()
{
      var roleId=jQuery("#roleId").val();
      var url=base + "/roleManager/getFunctionList.do?roleId="+roleId; 
        jQuery.post(
                      url, 
                      function(result){
                         var data = eval("("+result+")");
                         if(data.STATUS==0)
                         {
                         	var funList=data.USER_FUNCTION_LIST; 
                            $.fn.zTree.init($("#funListTree"), setting, funList);
                            return ;
                         }
                         alert(data.MSG);  
        }); 
}


function saveRoleInfo()
{
     var zTree = $.fn.zTree.getZTreeObj("funListTree");
     var nodes =zTree.getCheckedNodes();
    // var arr =  zTree.transformToArray(nodes);
     var data = handlerTreeData(nodes); 
     var action =jQuery("#roleInfoForm").attr("action");
       jQuery.post(
                      action, 
                      {
                       roleId:jQuery("#roleId").val(),
                       roleName:jQuery("#roleName").val(),
                       roleDesc:jQuery("#roleDesc").val(),
                       roleFunList:JSON.stringify(data)
                       },
                      function(result){
                         var data = eval("("+result+")");
                         if(data.STATUS==0)
                         {
                         	alert("保存成功!");
                         	location.href=base+"/roleManager.do";
                            return ;
                         }
                         alert(data.MSG);  
        }); 
}


function handlerTreeData(arr)
{
   var data = new Array();
   var map =null;
   var vMap= new Map();
   jQuery(arr).each(function(index,obj)
    {
              if(!vMap.contains(jQuery(obj).attr("id")))
              {
                 map = new Map();
                 map.put("funId",jQuery(obj).attr("id"));
                 map.put("funName",jQuery(obj).attr("name"));
                 data.push(eval("("+map._toJson()+")"));
                 vMap.put(jQuery(obj).attr("id"),jQuery(obj).attr("id"));
              }
             
    }
   	);
    return data;
}



